import TreeNode from "../common/tree_node";
import { n1 } from "../common/tree_node";

//思路，递归得到左右最大节点数。然后跟当前最大数比较。本质是比较节点数最大

function diameterOfBinaryTree(root: TreeNode | null): number {
  let nums = 0

  function deep_loop(root: TreeNode | null): number{//返回节点高度
    if (root == null) {
      return 0
    }
    let leftH = deep_loop(root.left)
    let rightH = deep_loop(root.right)
    nums = Math.max(leftH + rightH + 1,nums)//当前节点的高度和最大节点数比较
    return Math.max(leftH,rightH) + 1
  }
  deep_loop(root)
  return nums
};